package buttons.control;

import buttons.view.V_ToggleButton;

/**************************************
TOGGLE BUTTON CLASS Controller 
***************************************/
public class C_ToggleButton extends C_Button
{
	boolean toggle;
	
	public C_ToggleButton(V_ToggleButton viewButton){
	 super(viewButton);
	}
	
	@Override
	public void onInteract (float mouseXLoc, float mouseYLoc, String interID)
	{
	 V_ToggleButton button = (V_ToggleButton)vFeature;
	 boolean mouseOver = vFeature.contains(mouseXLoc, mouseYLoc);
	 button.setOver(mouseOver);
	 if(mouseOver)
	 {  
	     if(interID.equals("leftClick"))
	     {
	       toggle = !toggle;
		   button.setToggle(toggle);
	       if(toggle == false) triggerEvent("toggleOff");
	       else triggerEvent("toggleOn");
	     }
	     if(interID.equals("leftPressed"))
	     {
	       button.setOffset(-20);
	     }
	     else // if mouse over...
	     {
	         // set the background to an "over" color
	         if(toggle) button.setOffset(50);
	         else button.setOffset(20);
	         // start a tooltip counter
	         if(c_toolTip != null)
             {
		         if(c_toolTip.checkForTip(mouseXLoc, mouseYLoc))
		         {
		             if(tooltipText.length() > 0) // if the button HAS a set tooltip display it
		             {
		               c_toolTip.setName(tooltipText);
		               c_toolTip.setActive(true);
		             }
		         }
		         else c_toolTip.setActive(false);
             }
	     }          
	 }
	 else // if mouse not over the button
	 { 
	   button.setOffset(0);
	   //if(v_toolTip.getText().equals(tooltip)) c_toolTip.setActive(false);
	 }
	}
	public void forceToggleOn()
	{
	  toggle = true;
	  ((V_ToggleButton)vFeature).setToggle(true);
	  triggerEvent("toggleOn"); 
	}
	public void forceToggleOff()
	{
	 toggle = false;
	 ((V_ToggleButton)vFeature).setToggle(false);
	 triggerEvent("toggleOff");
	}
	public void softToggle(boolean val)
	{
	 toggle = val;
	 ((V_ToggleButton)vFeature).setToggle(val);
	}
	public boolean getToggle()
	{
	 return toggle;
	}
}
